/*!
 * froala_editor v3.0.6 (https://www.froala.com/wysiwyg-editor)
 * License https://froala.com/wysiwyg-editor/terms/
 * Copyright 2014-2019 Froala Labs
 */

!
function(e, t) {
    "object" == typeof exports && "undefined" != typeof module ? t(require("froala-editor")) : "function" == typeof define && define.amd ? define(["froala-editor"], t) : t(e.FroalaEditor)
} (this,
function(x) {
    "use strict";
    x = x && x.hasOwnProperty("default") ? x["default"] : x,
    Object.assign(x.POPUP_TEMPLATES, {
        "file.insert": "[_BUTTONS_][_UPLOAD_LAYER_][_PROGRESS_BAR_]"
    }),
    Object.assign(x.DEFAULTS, {
        fileUpload: !0,
        fileUploadURL: null,
        fileUploadParam: "file",
        fileUploadParams: {},
        fileUploadToQiniu: !1,
        fileUploadMethod: "POST",
        fileMaxSize: 10485760,
        fileAllowedTypes: ["*"],
        fileInsertButtons: ["fileBack", "|"],
        fileUseSelectedText: !1
    }),
    x.PLUGINS.file = function(p) {
        var r, d = p.$,
        l = "https://i.froala.com/upload",
        u = 2,
        c = 3,
        v = 4,
        f = 5,
        g = 6,
        i = {};
        function h() {
            var e = p.popups.get("file.insert");
            e || (e = T()),
            e.find(".fr-layer.fr-active").removeClass("fr-active").addClass("fr-pactive"),
            e.find(".fr-file-progress-bar-layer").addClass("fr-active"),
            e.find(".fr-buttons").hide(),
            o(p.language.translate("Uploading"), 0)
        }
        function n(e) {
            var t = p.popups.get("file.insert");
            t && (t.find(".fr-layer.fr-pactive").addClass("fr-active").removeClass("fr-pactive"), t.find(".fr-file-progress-bar-layer").removeClass("fr-active"), t.find(".fr-buttons").show(), e && (p.events.focus(), p.popups.hide("file.insert")))
        }
        function o(e, t) {
            var i = p.popups.get("file.insert");
            if (i) {
                var r = i.find(".fr-file-progress-bar-layer");
                r.find("h3").text(e + (t ? " " + t + "%": "")),
                r.removeClass("fr-error"),
                t ? (r.find("div").removeClass("fr-indeterminate"), r.find("div > span").css("width", t + "%")) : r.find("div").addClass("fr-indeterminate")
            }
        }
        function b(e, t, i) {
            p.edit.on(),
            p.events.focus(!0),
            p.selection.restore(),
            p.opts.fileUseSelectedText && p.selection.text().length && (t = p.selection.text()),
            p.html.insert('<a href="' + e + '" target="_blank" id="fr-inserted-file" class="fr-file">' + t + "</a>");
            var r = p.$el.find("#fr-inserted-file");
            r.removeAttr("id"),
            p.popups.hide("file.insert"),
            p.undo.saveStep(),
            k(),
            p.events.trigger("file.inserted", [r, i])
        }
        function m(e) {
            var t = this.status,
            i = this.response,
            r = this.responseXML,
            o = this.responseText;
            try {
                if (p.opts.fileUploadToQiniu){
                    var m = JSON.parse(o);
					if (!m.error) {
                    var n = function s(e) {
                        try {
                            return ! 1 === p.events.trigger("file.uploadedToQiniu", e, !0) ? (p.edit.on(), !1) : e
                        } catch(r) {
                            return S(v, e),
                            !1
                        }
                    } (m);
                    n && b(p.opts.fileUploadToQiniu.domain+n.key, e, i || r)
                } else{ S(v, i || r);}
                }else if (200 <= t && t < 300) {
                    var a = function l(e) {
                        try {
                            if (!1 === p.events.trigger("file.uploaded", [e], !0)) return p.edit.on(),
                            !1;
                            var t = JSON.parse(e);
                            return t.link ? t: (S(u, e), !1)
                        } catch(i) {
                            return S(v, e),
                            !1
                        }
                    } (o);
                    a && b(a.link, e, i || o)
                } else S(c, i || o)
            } catch(f) {
                S(v, i || o)
            }
        }
        function y() {
            S(v, this.response || this.responseText || this.responseXML)
        }
        function U(e) {
            if (e.lengthComputable) {
                var t = e.loaded / e.total * 100 | 0;
                o(p.language.translate("Uploading"), t)
            }
        }
        function S(e, t) {
            p.edit.on(),
            function r(e) {
                h();
                var t = p.popups.get("file.insert").find(".fr-file-progress-bar-layer");
                t.addClass("fr-error");
                var i = t.find("h3");
                i.text(e),
                p.events.disableBlur(),
                i.focus()
            } (p.language.translate("Something went wrong. Please try again.")),
            p.events.trigger("file.error", [{
                code: e,
                message: i[e]
            },
            t])
        }
        function C() {
            p.edit.on(),
            n(!0)
        }
        function a(e) {
            if (void 0 !== e && 0 < e.length) {
                if (!1 === p.events.trigger("file.beforeUpload", [e])) return ! 1;
                var t, i = e[0];
                if ((null === p.opts.fileUploadURL || p.opts.fileUploadURL === l) && !p.opts.fileUploadToQiniu) return function s(o) {
                    var n = new FileReader;
                    n.onload = function() {
                        for (var e = n.result,
                        t = atob(n.result.split(",")[1]), i = [], r = 0; r < t.length; r++) i.push(t.charCodeAt(r));
                        e = window.URL.createObjectURL(new Blob([new Uint8Array(i)], {
                            type: o.type
                        })),
                        p.file.insert(e, o.name, null)
                    },
                    h(),
                    n.readAsDataURL(o)
                } (i),
                !1;
                if (i.size > p.opts.fileMaxSize) return S(f),
                !1;
                if (p.opts.fileAllowedTypes.indexOf("*") < 0 && p.opts.fileAllowedTypes.indexOf(i.type.replace(/file\//g, "")) < 0) return S(g),
                !1;
                if (p.drag_support.formdata && (t = p.drag_support.formdata ? new FormData: null), t) {
                    var r;
                    if (!1 !== p.opts.fileUploadToQiniu) for (r in t.append("X-Requested-With", "xhr"), t.append("Content-Type", i.type), p.opts.fileUploadToQiniu.params) p.opts.fileUploadToQiniu.params.hasOwnProperty(r) && t.append(r, p.opts.fileUploadToQiniu.params[r]);
                    for (r in p.opts.fileUploadParams) p.opts.fileUploadParams.hasOwnProperty(r) && t.append(r, p.opts.fileUploadParams[r]);
                    t.append(p.opts.fileUploadParam, i);
                    var o = p.opts.fileUploadURL;
                    p.opts.fileUploadToQiniu && (o = 'http://up.qiniu.com');
					if (!1 !== p.opts.fileUploadToQiniu){
						jQuery.ajax({
							url: p.opts.fileUploadToQiniu.getTokenUrl,
							async: !1,
							dataType: "json",
							success: function(c) {
								t.append("token", c.uptoken);
							}
						})
					}
                    var n = p.core.getXHR(o, p.opts.fileUploadMethod);
                    n.onload = function() {
                        m.call(n, i.name)
                    },
                    n.onerror = y,
                    n.upload.onprogress = U,
                    n.onabort = C,
                    h();
                    var a = p.popups.get("file.insert");
                    a && (a.off("abortUpload"), a.on("abortUpload",
                    function() {
                        4 !== n.readyState && n.abort()
                    })),
                    n.send(t)
                }
            }
        }
        function s() {
            n()
        }
        function T(e) {
            if (e) return p.popups.onHide("file.insert", s),
            !0;
            var t;
            p.opts.fileUpload || p.opts.fileInsertButtons.splice(p.opts.fileInsertButtons.indexOf("fileUpload"), 1),
            t = '<div class="fr-buttons fr-tabs">' + p.button.buildList(p.opts.fileInsertButtons) + "</div>";
            var i = "";
            p.opts.fileUpload && (i = '<div class="fr-file-upload-layer fr-layer fr-active" id="fr-file-upload-layer-' + p.id + '"><strong>' + p.language.translate("Drop file") + "</strong><br>(" + p.language.translate("or click") + ')<div class="fr-form"><input type="file" name="' + p.opts.fileUploadParam + '" accept="' + (0 <= p.opts.fileAllowedTypes.indexOf("*") ? "/": "") + p.opts.fileAllowedTypes.join(", ").toLowerCase() + '" tabIndex="-1" aria-labelledby="fr-file-upload-layer-' + p.id + '" role="button"></div></div>');
            var r = {
                buttons: t,
                upload_layer: i,
                progress_bar: '<div class="fr-file-progress-bar-layer fr-layer"><h3 tabIndex="-1" class="fr-message">Uploading</h3><div class="fr-loader"><span class="fr-progress"></span></div><div class="fr-action-buttons"><button type="button" class="fr-command fr-dismiss" data-cmd="fileDismissError" tabIndex="2" role="button">OK</button></div></div>'
            },
            o = p.popups.create("file.insert", r);
            return function n(i) {
                p.events.$on(i, "dragover dragenter", ".fr-file-upload-layer",
                function() {
                    return d(this).addClass("fr-drop"),
                    !1
                },
                !0),
                p.events.$on(i, "dragleave dragend", ".fr-file-upload-layer",
                function() {
                    return d(this).removeClass("fr-drop"),
                    !1
                },
                !0),
                p.events.$on(i, "drop", ".fr-file-upload-layer",
                function(e) {
                    e.preventDefault(),
                    e.stopPropagation(),
                    d(this).removeClass("fr-drop");
                    var t = e.originalEvent.dataTransfer;
                    t && t.files && (i.data("instance") || p).file.upload(t.files)
                },
                !0),
                p.helpers.isIOS() && p.events.$on(i, "touchstart", '.fr-file-upload-layer input[type="file"]',
                function() {
                    d(this).trigger("click")
                }),
                p.events.$on(i, "change", '.fr-file-upload-layer input[type="file"]',
                function() {
                    if (this.files) {
                        var e = i.data("instance") || p;
                        e.events.disableBlur(),
                        i.find("input:focus").blur(),
                        e.events.enableBlur(),
                        e.file.upload(this.files)
                    }
                    d(this).val("")
                },
                !0)
            } (o),
            o
        }
        function t(e) {
            p.node.hasClass(e, "fr-file")
        }
        function w(e) {
            var t = e.originalEvent.dataTransfer;
            if (t && t.files && t.files.length) {
                var i = t.files[0];
                if (i && "undefined" != typeof i.type) {
                    if (i.type.indexOf("image") < 0) {
                        if (!p.opts.fileUpload) return e.preventDefault(),
                        e.stopPropagation(),
                        !1;
                        p.markers.remove(),
                        p.markers.insertAtPoint(e.originalEvent),
                        p.$el.find(".fr-marker").replaceWith(x.MARKERS),
                        p.popups.hideAll();
                        var r = p.popups.get("file.insert");
                        return r || (r = T()),
                        p.popups.setContainer("file.insert", p.$sc),
                        p.popups.show("file.insert", e.originalEvent.pageX, e.originalEvent.pageY),
                        h(),
                        a(t.files),
                        e.preventDefault(),
                        e.stopPropagation(),
                        !1
                    }
                } else i.type.indexOf("image") < 0 && (e.preventDefault(), e.stopPropagation())
            }
        }
        function k() {
            var e, t = Array.prototype.slice.call(p.el.querySelectorAll("a.fr-file")),
            i = [];
            for (e = 0; e < t.length; e++) i.push(t[e].getAttribute("href"));
            if (r) for (e = 0; e < r.length; e++) i.indexOf(r[e].getAttribute("href")) < 0 && p.events.trigger("file.unlink", [r[e]]);
            r = t
        }
        return i[1] = "File cannot be loaded from the passed link.",
        i[u] = "No link in upload response.",
        i[c] = "Error during file upload.",
        i[v] = "Parsing response failed.",
        i[f] = "File is too large.",
        i[g] = "File file type is invalid.",
        i[7] = "Files can be uploaded only to same domain in IE 8 and IE 9.",
        {
            _init: function P() { !
                function e() {
                    p.events.on("drop", w),
                    p.events.$on(p.$win, "keydown",
                    function(e) {
                        var t = e.which,
                        i = p.popups.get("file.insert");
                        i && t === x.KEYCODE.ESC && i.trigger("abortUpload")
                    }),
                    p.events.on("destroy",
                    function() {
                        var e = p.popups.get("file.insert");
                        e && e.trigger("abortUpload")
                    })
                } (),
                p.events.on("link.beforeRemove", t),
                p.$wp && (k(), p.events.on("contentChanged", k)),
                T(!0)
            },
            showInsertPopup: function A() {
                var e = p.$tb.find('.fr-command[data-cmd="insertFile"]'),
                t = p.popups.get("file.insert");
                if (t || (t = T()), n(), !t.hasClass("fr-active")) if (p.popups.refresh("file.insert"), p.popups.setContainer("file.insert", p.$tb), e.isVisible) {
                    var i = p.button.getPosition(e),
                    r = i.left,
                    o = i.top;
                    p.popups.show("file.insert", r, o, e.outerHeight())
                } else p.position.forSelection(t),
                p.popups.show("file.insert")
            },
            upload: a,
            insert: b,
            back: function e() {
                p.events.disableBlur(),
                p.selection.restore(),
                p.events.enableBlur(),
                p.popups.hide("file.insert"),
                p.toolbar.showInline()
            },
            hideProgressBar: n
        }
    },
    x.DefineIcon("insertFile", {
        NAME: "file-o",
        FA5NAME: "file",
        SVG_KEY: "insertFile"
    }),
    x.RegisterCommand("insertFile", {
        title: "Upload File",
        undo: !1,
        focus: !0,
        refreshAfterCallback: !1,
        popup: !0,
        callback: function() {
            this.popups.isVisible("file.insert") ? (this.$el.find(".fr-marker").length && (this.events.disableBlur(), this.selection.restore()), this.popups.hide("file.insert")) : this.file.showInsertPopup()
        },
        plugin: "file"
    }),
    x.DefineIcon("fileBack", {
        NAME: "arrow-left",
        SVG_KEY: "back"
    }),
    x.RegisterCommand("fileBack", {
        title: "Back",
        undo: !1,
        focus: !1,
        back: !0,
        refreshAfterCallback: !1,
        callback: function() {
            this.file.back()
        },
        refresh: function(e) {
            this.opts.toolbarInline ? (e.removeClass("fr-hidden"), e.next(".fr-separator").removeClass("fr-hidden")) : (e.addClass("fr-hidden"), e.next(".fr-separator").addClass("fr-hidden"))
        }
    }),
    x.RegisterCommand("fileDismissError", {
        title: "OK",
        callback: function() {
            this.file.hideProgressBar(!0)
        }
    })
});